/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainForm.java
 *
 * Created on Oct 10, 2012, 8:49:53 AM
 */
package Gui;
import DAO.QuyDinhDAO;
import OBJECT.LichTrinh;
import Panel.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.Dimension;
import javax.swing.JPanel;

/**
 *
 * @author TAN
 */
public class MainForm extends javax.swing.JFrame implements ActionListener{
     TimKiemLichTrinh tklichtrinh;
         DangKiVanChuyenForm dkvanchuyen;
         String User ;
         String Pass;
        // String port;
         String DataBase;
         String Host;
         public LichTrinh lt;
    /** Creates new form MainForm */
    JInternalFrameForm form = null;
    private String user = "";
    private String pass = "";
    private String port = "";
    public String database = "";
    private String host = "";
    
    private DangNhap dn = null;
    private DKKHachHang dkkh = null;
    private DangKiVanChuyenForm dkvc = null;
    private DangKyLichLamViec dkllv = null;
    private QuanLyLichTrinh qllt = null;
    private QuanLyNhanVien qlnv = null;
    private SuaQuyDinh sqd = null;
    private ThongKeLoiNhuan tkln = null;
    private TimKiemLichTrinh tklt = null;
    private UpdateAndDeleteKH uadkh = null;
    private QuanLyTuyenDuong qltd = null;
    private QuanLyTau qlt = null;
    private Dimension screen = null;
    public MainForm(String User ,String Pass,String port,String DataBase,String Host)
    {

         //initComponents();
         
      // QuanLyNhanVien ql=new QuanLyNhanVien(User, Pass, port, DataBase, Host);
      //ql.setVisible(true);
      //this.add(ql);

        initComponents();

        screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(screen);


        //DKKHachHang kh=new DKKHachHang(User, Pass, port, DataBase, Host);
        //kh.setVisible(true);
        //this.add(kh);
     //UpdateAndDeleteKH kh= new UpdateAndDeleteKH(User, Pass, port, DataBase, Host);
    // kh.setVisible(true);
     //this.add(kh);

        this.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize());


        
        
        if(form == null){
            form = new JInternalFrameForm();
        }
        
        AnHienChucNang();
        
        this.user = User;
        this.pass = Pass;
        this.port = port;
        this.database = DataBase;
        this.host = Host;
    }


       // QuanLyLichTrinh dkvc=new QuanLyLichTrinh();
       // DangKiVanChuyenForm lichtrinh = new DangKiVanChuyenForm( User , Pass, port, DataBase, Host,lt);

    //  QuanLyLichTrinh lichtrinh=new QuanLyLichTrinh(User , Pass, port, DataBase, Host);
       // VanChuyen lichtrinh = new VanChuyen(User, Pass, port, DataBase, Host);
        //lichtrinh.setVisible(true);
        //this.add(lichtrinh);

       // QuanLyLichTrinh dkvc=new QuanLyLichTrinh();
      //  DangKiVanChuyenForm dkvc = new DangKiVanChuyenForm();

       //dkvc.setVisible(true);
        //this.add(dkvc);


    public void AnHienChucNang(){
        if(util.Global.isLogin){
            JMILogin.setVisible(false);
            JMILogout.setVisible(true);
            JMFunction.setVisible(true);
        }else{
            JMILogin.setVisible(true);
            JMILogout.setVisible(false);
            JMFunction.setVisible(false);
        }

    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JDPDesktop = new javax.swing.JDesktopPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        JMFile = new javax.swing.JMenu();
        JMILogin = new javax.swing.JMenuItem();
        JMILogout = new javax.swing.JMenuItem();
        JMIExit = new javax.swing.JMenuItem();
        JMFunction = new javax.swing.JMenu();
        JMIDangKyKhachHang = new javax.swing.JMenuItem();
        JMIDangKyVanChuyen = new javax.swing.JMenuItem();
        JMITimKiemLichTrinh = new javax.swing.JMenuItem();
        JMIDangKyLichLamViec = new javax.swing.JMenuItem();
        JMIQuanLyLichTrinh = new javax.swing.JMenuItem();
        JMIQuanLyNhanVien = new javax.swing.JMenuItem();
        JMISuaQuyDinh = new javax.swing.JMenuItem();
        JMIThongKeLoiNhuan = new javax.swing.JMenuItem();
        JMICapNhatDanhSachKhachHang = new javax.swing.JMenuItem();
        JMIQuanLyTuyenDuong = new javax.swing.JMenuItem();
        JMIQuanLyTau = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(800, 600));
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        JDPDesktop.setBackground(new java.awt.Color(255, 255, 255));
        getContentPane().add(JDPDesktop);

        JMFile.setText("Tập tin");

        JMILogin.setText("Đăng nhập");
        JMILogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMILoginActionPerformed(evt);
            }
        });
        JMFile.add(JMILogin);

        JMILogout.setText("Đăng xuất");
        JMILogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMILogoutActionPerformed(evt);
            }
        });
        JMFile.add(JMILogout);

        JMIExit.setText("Thoát");
        JMIExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIExitActionPerformed(evt);
            }
        });
        JMFile.add(JMIExit);

        jMenuBar1.add(JMFile);

        JMFunction.setText("Chức năng");

        JMIDangKyKhachHang.setText("Đăng ký khách hàng");
        JMIDangKyKhachHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIDangKyKhachHangActionPerformed(evt);
            }
        });
        JMFunction.add(JMIDangKyKhachHang);

        JMIDangKyVanChuyen.setText("Đăng ký vận chuyển");
        JMIDangKyVanChuyen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIDangKyVanChuyenActionPerformed(evt);
            }
        });
        JMFunction.add(JMIDangKyVanChuyen);

        JMITimKiemLichTrinh.setText("Tìm kiếm lịch trình");
        JMITimKiemLichTrinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMITimKiemLichTrinhActionPerformed(evt);
            }
        });
        JMFunction.add(JMITimKiemLichTrinh);

        JMIDangKyLichLamViec.setText("Đăng ký lịch làm việc");
        JMIDangKyLichLamViec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIDangKyLichLamViecActionPerformed(evt);
            }
        });
        JMFunction.add(JMIDangKyLichLamViec);

        JMIQuanLyLichTrinh.setText("Quản lý lịch trình");
        JMIQuanLyLichTrinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIQuanLyLichTrinhActionPerformed(evt);
            }
        });
        JMFunction.add(JMIQuanLyLichTrinh);

        JMIQuanLyNhanVien.setText("Quản lý nhân viên");
        JMIQuanLyNhanVien.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIQuanLyNhanVienActionPerformed(evt);
            }
        });
        JMFunction.add(JMIQuanLyNhanVien);

        JMISuaQuyDinh.setText("Sửa quy định");
        JMISuaQuyDinh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMISuaQuyDinhActionPerformed(evt);
            }
        });
        JMFunction.add(JMISuaQuyDinh);

        JMIThongKeLoiNhuan.setText("Thống kê lợi nhuận");
        JMIThongKeLoiNhuan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIThongKeLoiNhuanActionPerformed(evt);
            }
        });
        JMFunction.add(JMIThongKeLoiNhuan);

        JMICapNhatDanhSachKhachHang.setText("Cập nhật danh sách khách hàng");
        JMICapNhatDanhSachKhachHang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMICapNhatDanhSachKhachHangActionPerformed(evt);
            }
        });
        JMFunction.add(JMICapNhatDanhSachKhachHang);

        JMIQuanLyTuyenDuong.setText("Quản lý tuyến đường");
        JMIQuanLyTuyenDuong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIQuanLyTuyenDuongActionPerformed(evt);
            }
        });
        JMFunction.add(JMIQuanLyTuyenDuong);

        JMIQuanLyTau.setText("Quản lý Tàu");
        JMIQuanLyTau.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JMIQuanLyTauActionPerformed(evt);
            }
        });
        JMFunction.add(JMIQuanLyTau);

        jMenuBar1.add(JMFunction);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JMILoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMILoginActionPerformed
        // TODO add your handling code here:
//        if(dn == null){
            dn = new DangNhap(user, pass, port, database, host,this);
//        }
        HienThiForm(dn);
    }//GEN-LAST:event_JMILoginActionPerformed

    private void JMIExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIExitActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_JMIExitActionPerformed

    private void JMILogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMILogoutActionPerformed
        // TODO add your handling code here:
        form.dispose();
        util.Global.customer = null;
        util.Global.employee = null;
        util.Global.isLogin = false;
        AnHienChucNang();
    }//GEN-LAST:event_JMILogoutActionPerformed

    private void JMIDangKyKhachHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIDangKyKhachHangActionPerformed
        // TODO add your handling code here:
        if(dkkh == null){
            dkkh = new DKKHachHang(user, pass, port, database, host);
        }
        
        HienThiForm(dkkh);
    }//GEN-LAST:event_JMIDangKyKhachHangActionPerformed

    private void JMIDangKyVanChuyenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIDangKyVanChuyenActionPerformed
        // TODO add your handling code here:
        if(dkvc == null){
            dkvc = new DangKiVanChuyenForm(user, pass, port, database, host,lt);
        }
        HienThiForm(dkvc);
    }//GEN-LAST:event_JMIDangKyVanChuyenActionPerformed

    private void JMITimKiemLichTrinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMITimKiemLichTrinhActionPerformed
        // TODO add your handling code here:
        if(tklt == null){
            tklt = new TimKiemLichTrinh(user, pass, port, database, host,this);
        }
      
        HienThiForm(tklt);
    }//GEN-LAST:event_JMITimKiemLichTrinhActionPerformed

    private void JMIDangKyLichLamViecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIDangKyLichLamViecActionPerformed
        // TODO add your handling code here:
        if(dkllv == null){
            dkllv = new DangKyLichLamViec(user, pass, port, database, host);
        }
           
        HienThiForm(dkllv);
    }//GEN-LAST:event_JMIDangKyLichLamViecActionPerformed

    private void JMIQuanLyLichTrinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIQuanLyLichTrinhActionPerformed
        // TODO add your handling code here:
        if(qllt == null){
            qllt = new QuanLyLichTrinh(user, pass, port, database, host);
        }
        HienThiForm(qllt);
    }//GEN-LAST:event_JMIQuanLyLichTrinhActionPerformed

    private void JMIQuanLyNhanVienActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIQuanLyNhanVienActionPerformed
        // TODO add your handling code here:
        if(qlnv == null){
            qlnv = new QuanLyNhanVien(user, pass, port, database, host);
        }
        HienThiForm(qlnv);
    }//GEN-LAST:event_JMIQuanLyNhanVienActionPerformed

    private void JMISuaQuyDinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMISuaQuyDinhActionPerformed
        // TODO add your handling code here:
        if(sqd == null){
            sqd = new SuaQuyDinh(user, pass, port, database, host);
        }
        HienThiForm(sqd);
    }//GEN-LAST:event_JMISuaQuyDinhActionPerformed

    private void JMIThongKeLoiNhuanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIThongKeLoiNhuanActionPerformed
        // TODO add your handling code here:
        if(tkln == null){
            tkln = new ThongKeLoiNhuan();
        }
        HienThiForm(tkln);
    }//GEN-LAST:event_JMIThongKeLoiNhuanActionPerformed

    private void JMICapNhatDanhSachKhachHangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMICapNhatDanhSachKhachHangActionPerformed
        // TODO add your handling code here:
        if(uadkh == null){
            uadkh = new UpdateAndDeleteKH(user, pass, port, database, host);
        }
        HienThiForm(uadkh);
    }//GEN-LAST:event_JMICapNhatDanhSachKhachHangActionPerformed

    private void JMIQuanLyTuyenDuongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIQuanLyTuyenDuongActionPerformed
        // TODO add your handling code here:
        if(qltd == null){
            qltd = new QuanLyTuyenDuong(user, pass, port, database, host);
        }
        HienThiForm(qltd);
    }//GEN-LAST:event_JMIQuanLyTuyenDuongActionPerformed

    private void JMIQuanLyTauActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JMIQuanLyTauActionPerformed
        // TODO add your handling code here:
        if(qlt == null){
            qlt = new QuanLyTau(user, pass, port, database, host);
        }
        
        HienThiForm(qlt);
    }//GEN-LAST:event_JMIQuanLyTauActionPerformed

    public void HienThiForm(JPanel p){
        
        form.setContentPane(p);
        Dimension dimension = p.getPreferredSize();
        dimension.height += 40;
        dimension.width += 20;
        form.setSize(dimension);
        
        int left = (screen.width - form.getWidth()) / 2;
        int top = (screen.height - form.getHeight()) / 2;
        
        form.setLocation(left, top);
        
        JDPDesktop.removeAll();
        
        JDPDesktop.add(form);
        form.setVisible(true);
    }
    
    public void enableFuntions(){
        form.dispose();
        AnHienChucNang();
        if(util.Global.customer != null){
            HienThiChucNangCuaKhachHang();
        }else{
            HienThiChucNangCuaNhanVien();
        }
    }
    
    public void HienThiChucNangCuaKhachHang(){
        JMIDangKyKhachHang.setVisible(true);
        JMIDangKyVanChuyen.setVisible(true);
        JMICapNhatDanhSachKhachHang.setVisible(false);
        JMIDangKyLichLamViec.setVisible(false);
        JMIQuanLyLichTrinh.setVisible(false);
        JMIQuanLyNhanVien.setVisible(false);
        JMISuaQuyDinh.setVisible(false);
        JMIThongKeLoiNhuan.setVisible(false);
        JMITimKiemLichTrinh.setVisible(true);
        JMIQuanLyTuyenDuong.setVisible(false);
        JMIQuanLyTau.setVisible(false);
    }
    
    public void HienThiChucNangCuaNhanVien(){
        if(util.Global.employee.getLoaiNhanVien() == 3){
            JMIQuanLyNhanVien.setVisible(true);
            JMISuaQuyDinh.setVisible(true);
            JMICapNhatDanhSachKhachHang.setVisible(true);
            JMIThongKeLoiNhuan.setVisible(true);
            JMIDangKyLichLamViec.setVisible(false);
            JMIQuanLyLichTrinh.setVisible(true);
            JMIQuanLyTuyenDuong.setVisible(true);
            JMIQuanLyTau.setVisible(true);
        }else{
            JMIQuanLyNhanVien.setVisible(false);
            JMISuaQuyDinh.setVisible(false);
            JMICapNhatDanhSachKhachHang.setVisible(false);
            JMIThongKeLoiNhuan.setVisible(false);
            JMIDangKyLichLamViec.setVisible(true);
            JMIQuanLyLichTrinh.setVisible(false);
            JMIQuanLyTuyenDuong.setVisible(false);
            JMIQuanLyTau.setVisible(false);
        }
        JMIDangKyKhachHang.setVisible(false);
        JMIDangKyVanChuyen.setVisible(false);
        JMITimKiemLichTrinh.setVisible(true);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainForm("sa", "123456789", "1433", "TRANSPORT1", "localhost").setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane JDPDesktop;
    private javax.swing.JMenu JMFile;
    private javax.swing.JMenu JMFunction;
    private javax.swing.JMenuItem JMICapNhatDanhSachKhachHang;
    private javax.swing.JMenuItem JMIDangKyKhachHang;
    private javax.swing.JMenuItem JMIDangKyLichLamViec;
    private javax.swing.JMenuItem JMIDangKyVanChuyen;
    private javax.swing.JMenuItem JMIExit;
    private javax.swing.JMenuItem JMILogin;
    private javax.swing.JMenuItem JMILogout;
    private javax.swing.JMenuItem JMIQuanLyLichTrinh;
    private javax.swing.JMenuItem JMIQuanLyNhanVien;
    private javax.swing.JMenuItem JMIQuanLyTau;
    private javax.swing.JMenuItem JMIQuanLyTuyenDuong;
    private javax.swing.JMenuItem JMISuaQuyDinh;
    private javax.swing.JMenuItem JMIThongKeLoiNhuan;
    private javax.swing.JMenuItem JMITimKiemLichTrinh;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
       System.out.println(lt.getMaLichTrinh()+"mainform");
       dkvanchuyen=new DangKiVanChuyenForm(User, Pass, port, DataBase, Host,lt);
       //dkvanchuyen.lichtrinh=lt;
       dkvanchuyen.setVisible(true);
       this.remove(tklichtrinh);
        this.invalidate();
       this.add(dkvanchuyen);
       this.validate();
        this.repaint();
       System.out.println("sahdahd");
      
       System.out.println("sahdahd");
    }
}
